﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Downloader.Framework.Core;

namespace Downloader.Framework.Queries
{
   public interface IEntityConvert<in T>
   {
       void From(T source);
   }

   public static class EntityConvertExtentions
   {
       public static IList<S> From<T, Tid, S>(this IQueryable<T> q)
           where T : EntityBase<Tid>
           where S : IEntityConvert<T>, new()
       {
           return q.ToArray().Select(From<T, Tid, S>).ToList();
       }

       static S From<T, Tid, S>(T item)
           where T : EntityBase<Tid>
           where S : IEntityConvert<T>, new()
       {
           var s = new S();
           s.From(item);
           return s;
       }
   }
}
